from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-23 14:13:09.048350
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 23, Sep, 2021
Time: 14:13:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3117
Nobs: 423.000 HQIC: -46.8326
Log likelihood: 4665.16 FPE: 3.25936e-21
AIC: -47.1728 Det(Omega_mle): 2.64122e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.430267 0.092226 4.665 0.000
L1.Burgenland 0.105876 0.047675 2.221 0.026
L1.Kärnten -0.114482 0.023870 -4.796 0.000
L1.Niederösterreich 0.156035 0.102165 1.527 0.127
L1.Oberösterreich 0.112790 0.100156 1.126 0.260
L1.Salzburg 0.283519 0.050096 5.659 0.000
L1.Steiermark 0.032056 0.066541 0.482 0.630
L1.Tirol 0.109565 0.052780 2.076 0.038
L1.Vorarlberg -0.103134 0.047176 -2.186 0.029
L1.Wien -0.006004 0.091473 -0.066 0.948
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.007347 0.211677 0.035 0.972
L1.Burgenland -0.048158 0.109423 -0.440 0.660
L1.Kärnten 0.036758 0.054785 0.671 0.502
L1.Niederösterreich -0.214707 0.234487 -0.916 0.360
L1.Oberösterreich 0.481015 0.229876 2.092 0.036
L1.Salzburg 0.305862 0.114980 2.660 0.008
L1.Steiermark 0.116653 0.152724 0.764 0.445
L1.Tirol 0.315882 0.121140 2.608 0.009
L1.Vorarlberg 0.003222 0.108279 0.030 0.976
L1.Wien 0.007516 0.209947 0.036 0.971
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240581 0.046842 5.136 0.000
L1.Burgenland 0.092027 0.024214 3.801 0.000
L1.Kärnten -0.002186 0.012123 -0.180 0.857
L1.Niederösterreich 0.212774 0.051890 4.101 0.000
L1.Oberösterreich 0.160152 0.050869 3.148 0.002
L1.Salzburg 0.034413 0.025444 1.352 0.176
L1.Steiermark 0.020568 0.033796 0.609 0.543
L1.Tirol 0.069574 0.026807 2.595 0.009
L1.Vorarlberg 0.058635 0.023961 2.447 0.014
L1.Wien 0.114860 0.046459 2.472 0.013
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183622 0.045798 4.009 0.000
L1.Burgenland 0.047468 0.023674 2.005 0.045
L1.Kärnten -0.006679 0.011853 -0.564 0.573
L1.Niederösterreich 0.140036 0.050733 2.760 0.006
L1.Oberösterreich 0.317912 0.049735 6.392 0.000
L1.Salzburg 0.100849 0.024877 4.054 0.000
L1.Steiermark 0.130165 0.033043 3.939 0.000
L1.Tirol 0.076816 0.026210 2.931 0.003
L1.Vorarlberg 0.055399 0.023427 2.365 0.018
L1.Wien -0.045783 0.045424 -1.008 0.313
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204383 0.090853 2.250 0.024
L1.Burgenland -0.046922 0.046965 -0.999 0.318
L1.Kärnten -0.034997 0.023514 -1.488 0.137
L1.Niederösterreich 0.107781 0.100644 1.071 0.284
L1.Oberösterreich 0.162478 0.098665 1.647 0.100
L1.Salzburg 0.251722 0.049350 5.101 0.000
L1.Steiermark 0.082839 0.065550 1.264 0.206
L1.Tirol 0.127073 0.051994 2.444 0.015
L1.Vorarlberg 0.115519 0.046474 2.486 0.013
L1.Wien 0.033935 0.090111 0.377 0.706
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033162 0.070217 0.472 0.637
L1.Burgenland 0.022939 0.036298 0.632 0.527
L1.Kärnten 0.052630 0.018173 2.896 0.004
L1.Niederösterreich 0.210244 0.077784 2.703 0.007
L1.Oberösterreich 0.333912 0.076255 4.379 0.000
L1.Salzburg 0.046645 0.038141 1.223 0.221
L1.Steiermark -0.004820 0.050662 -0.095 0.924
L1.Tirol 0.113287 0.040185 2.819 0.005
L1.Vorarlberg 0.065924 0.035918 1.835 0.066
L1.Wien 0.127027 0.069643 1.824 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189796 0.085673 2.215 0.027
L1.Burgenland 0.015223 0.044287 0.344 0.731
L1.Kärnten -0.057067 0.022173 -2.574 0.010
L1.Niederösterreich -0.118471 0.094905 -1.248 0.212
L1.Oberösterreich 0.191105 0.093039 2.054 0.040
L1.Salzburg 0.031809 0.046536 0.684 0.494
L1.Steiermark 0.295311 0.061812 4.778 0.000
L1.Tirol 0.487902 0.049029 9.951 0.000
L1.Vorarlberg 0.076458 0.043824 1.745 0.081
L1.Wien -0.109436 0.084972 -1.288 0.198
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155499 0.093828 1.657 0.097
L1.Burgenland -0.010969 0.048503 -0.226 0.821
L1.Kärnten 0.063713 0.024284 2.624 0.009
L1.Niederösterreich 0.195133 0.103939 1.877 0.060
L1.Oberösterreich -0.130163 0.101895 -1.277 0.201
L1.Salzburg 0.235537 0.050966 4.621 0.000
L1.Steiermark 0.154893 0.067696 2.288 0.022
L1.Tirol 0.047331 0.053696 0.881 0.378
L1.Vorarlberg 0.132701 0.047996 2.765 0.006
L1.Wien 0.158500 0.093061 1.703 0.089
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.482882 0.050893 9.488 0.000
L1.Burgenland -0.006343 0.026309 -0.241 0.809
L1.Kärnten -0.010089 0.013172 -0.766 0.444
L1.Niederösterreich 0.200773 0.056378 3.561 0.000
L1.Oberösterreich 0.255299 0.055269 4.619 0.000
L1.Salzburg 0.021808 0.027645 0.789 0.430
L1.Steiermark -0.021599 0.036719 -0.588 0.556
L1.Tirol 0.068016 0.029126 2.335 0.020
L1.Vorarlberg 0.061246 0.026033 2.353 0.019
L1.Wien -0.049303 0.050478 -0.977 0.329
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022660 0.079913 0.139714 0.131855 0.043667 0.074950 0.001781 0.183988
Kärnten 0.022660 1.000000 -0.042564 0.128620 0.047647 0.069245 0.453585 -0.091401 0.092151
Niederösterreich 0.079913 -0.042564 1.000000 0.282537 0.084035 0.263106 0.018611 0.140091 0.261058
Oberösterreich 0.139714 0.128620 0.282537 1.000000 0.178424 0.285470 0.155834 0.102120 0.137389
Salzburg 0.131855 0.047647 0.084035 0.178424 1.000000 0.124281 0.054407 0.106918 0.051868
Steiermark 0.043667 0.069245 0.263106 0.285470 0.124281 1.000000 0.132424 0.091740 -0.021727
Tirol 0.074950 0.453585 0.018611 0.155834 0.054407 0.132424 1.000000 0.044324 0.118195
Vorarlberg 0.001781 -0.091401 0.140091 0.102120 0.106918 0.091740 0.044324 1.000000 -0.045209
Wien 0.183988 0.092151 0.261058 0.137389 0.051868 -0.021727 0.118195 -0.045209 1.000000